<#include "../header.html">
<script type="text/javascript">
(function(window){
	var ext = "jpg,png,jpeg,gif";
	var size = 2;
	var upload={
		initUpload:function(){
			//触发弹出文件选择
			$("#uploadBtn").click(function(){
				//$("#ddd", window.parent.contentWindow).val();
				$("#imgFile").trigger("click");
			});
			$("#imgFile").change(Upload.checkUpload);
		},
		checkUpload:function(){
			var imgFile = $("#imgFile").val();
			//alert(imgFile);
			if(imgFile==null || JFT.isBlank(imgFile)){
				alert("请选择上传图片文件");
				return;
			}
			if(!JFT.checkFile(imgFile, ext)){
				alert("上传文件格式必须是["+ext+"]");
				return;
			}
			var fileSize = JFT.getFileSize("imgFile");
			alert(fileSize);
			if(fileSize!=-1 && fileSize/1024>size*1024){
				alert("上传图片文件最大不能超过"+size+"M");
				return;
			}
			//return;
			//document.uploadForm.action="uploadAction.do?method=upload";
			//document.uploadForm.submit();
		},
		handleUpload:function(code, imgId, imgSrc){
			if(code == 1){
				alert("");
				return;
			}else if(code == 2){
				alert("");
				return;
			}
			//$("#ddd", window.parent.contentWindow).val(imgId);
			//$("#imgURI", window.parent.contentWindow).val(imgSrc);
			//window.parent.renderImg(imgId, imgSrc);
		}
	};
	window.Upload = upload;
})(window);
$(function(){
	alert(resultCode !="-1");
	<#if resultCode !=-1>	
		var imgId=0;
		var imgSrc=null;
		var flag = ${resultCode!};
		if(flag!=-1){
			imgId="${imgId!}";
			imgSrc="${imgSrc!}";
			Upload.handleUpload(flag, imgId, imgSrc);
		}
	<#/if>	
	Upload.initUpload();
	
});
</script>
<button id="uploadBtn" class="e_btn-iframe">上传文件</button>
<form id="uploadForm" name="uploadForm" method="post" action="" enctype="multipart/form-data">
	<input type="file" id="imgFile" name="imgFile" class="e_hide"/>
</form>

<#include "../footer.html">